package org.itli.jnsocket.Controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.itli.jnsocket.Pojo.Outbound;
import org.itli.jnsocket.Result.Result;
import org.itli.jnsocket.Service.OutboundService;
import org.itli.jnsocket.Util.JWTUtil;
import org.itli.jnsocket.VTO.GoodCatrgory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@Tag(name = "出库操作")
@RequestMapping("/Outbound")
@RestController
public class OutboundController {

    OutboundService service;

    JWTUtil jwt = new JWTUtil();

    @Autowired
    public void setService(OutboundService service) {
        this.service = service;
    }

    //销售出库
    @PostMapping("/Out")
    @Operation(summary = "出库操作")
    public Result<String> OutBounds(@RequestHeader("Authorization") String token, @RequestBody Outbound outbound) {
        log.info("成功接受所有数据"+outbound);
        Map<String, Object> cliam;
        try{
            cliam = jwt.parseToken(token);
        } catch (Exception e) {
            return Result.success("令牌过期");
        }
        String username = (String) cliam.get("username");
        String s = service.OutBounds(outbound, username);
        log.info("service 层返回数据："+s);
        return Result.success(s);
    }
}
